//
//  OrderDetailsViewController.m
//  ai2ban
//
//  Created by Heartbeats on 2018/1/18.
//  Copyright © 2018年 mac book pro. All rights reserved.
//

#import "OrderDetailsViewController.h"
#import "OrderDetailGoodCell.h"
#import "OrderDetailHeadView.h"
#import "OrderDeatialInfoCell.h"

@interface OrderDetailsViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong) OrderDetailHeadView *footerView;
@property(nonatomic, strong) UITableView *tablewView;
@property(nonatomic, strong) NSArray *infos;
@end

@implementation OrderDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"订单详情";
    self.infos = @[@"姓名", @"联系电话", @"订单编号", @"订单时间", @"支付方式 "];
    self.view.backgroundColor = [UIColor colorWithRed:239/255.0 green:230/255.0 blue:230/255.0 alpha:1.0];
    self.tablewView = [[UITableView alloc] initWithFrame:self.view.frame];
    self.tablewView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tablewView.backgroundColor = [UIColor clearColor];
    self.tablewView.delegate = self;
    self.tablewView.dataSource = self;
    [self.view addSubview:self.tablewView];
    [self.tablewView registerNib:[UINib nibWithNibName:@"OrderDetailGoodCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"OrderDetailGoodCell"];
    [self.tablewView registerNib:[UINib nibWithNibName:@"OrderDeatialInfoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"OrderDeatialInfoCell"];
    self.tablewView.tableFooterView = [[NSBundle mainBundle] loadNibNamed:@"OrderDetailHeadView" owner:nil options:nil].lastObject;
}

- (void)setOrderModel:(OrderModel *)orderModel {
    _orderModel = orderModel;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return self.orderModel.productList.count;
    }
    if (section == 1) {
        return 1;
    }
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        OrderDetailGoodCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderDetailGoodCell" forIndexPath:indexPath];
        ProductModel *model = self.orderModel.productList[indexPath.row];
        if ([self.orderModel.orderType isEqualToString:@"1"] || [self.orderModel.orderType isEqualToString:@"2"]) {
           cell.isJiFenOrder = true;
        }else {
            cell.isJiFenOrder = false;
        }
        cell.model = model;
        return cell;
    }
    if (indexPath.section == 1) {
        OrderDeatialInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderDeatialInfoCell" forIndexPath:indexPath];
        cell.infoLab.text = @"340090989043";
        cell.infoLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
        cell.infoLab.textColor = mainColor;
        cell.detailLab.text = @"未使用";
        return cell;
    }
    OrderDeatialInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderDeatialInfoCell" forIndexPath:indexPath];
    cell.infoLab.text = self.infos[indexPath.row];
    if (indexPath.row == 0) {
        cell.detailLab.text = self.orderModel.contactName;
    }
    if (indexPath.row == 1) {
        cell.detailLab.text = self.orderModel.contactPhone;
    }
    if (indexPath.row == 2) {
        cell.detailLab.text = self.orderModel.orderNumber;
    }
    if (indexPath.row == 3) {
        cell.detailLab.text = self.orderModel.createTime;
    }
    if (indexPath.row == 4) {
        if ([self.orderModel.orderType isEqualToString:@"1"] || [self.orderModel.orderType isEqualToString:@"2"]) {
            cell.detailLab.text = @"星星豆兑换";
        }else {
            cell.detailLab.text = @"支付宝／微信支付";
        }
    }
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return nil;
    }
    if (section == 1) {
        return [[NSBundle mainBundle] loadNibNamed:@"OrderDetailHeadView" owner:nil options:nil].firstObject;
    }
    return [[NSBundle mainBundle] loadNibNamed:@"OrderDetailHeadView" owner:nil options:nil][1];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if (section == 0) {
        self.footerView = [[NSBundle mainBundle] loadNibNamed:@"OrderDetailHeadView" owner:nil options:nil][1];
//        self.footerView.getJiFenNumberLab.text = @"11";
//        self.footerView.payTypeLab.text = @"11";
//        self.footerView.moneyLab.text = @"11";
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        return 90;
    }
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 8;
    }
    return 60;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (!section) {
         return 60;
    }
    return 0;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
